package com.hbsx.oauth.util;

import java.sql.*;

public class NativeJDBCTest {

    public static void main(String[] args) throws SQLException {
        String url = "jdbc:mysql://localhost:3306/test";
        String username = "root";
        String password = "pass";
        String sql = "select * from user where user_name = ?";
        PreparedStatement ps =null;
        ResultSet rs = null;
        Connection con = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            con = DriverManager.getConnection(url,username,password);
            ps = con.prepareStatement(sql);
            ps.setString(1,"dalaoyang");
            rs = ps.executeQuery();
            while (rs.next()){
                System.out.println(rs.getString("user_name"));
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            if (rs!=null){
                rs.close();
            }
            if (ps!=null){
                ps.close();
            }
            if (con!=null){
                con.close();
            }
        }
    }
}
